<?php

namespace Admin\Controller;
use Think\Controller;
use Common\Api\Category;
class CategoryController extends CommonController{
	public function index() {
		$Category = new Category();
		$list = M('Category')->select();
		$this->assign('list', $Category->unlimitedForLevel($list) );
        $this->display();
	}

	public function add() {
		if(IS_AJAX) {
			$db = D('Category');
			if( !$db->create() ) {
				$this->error( $db->getError() );
			}else{
				if( !$db->add() ) {
					$this->error('新增失败！');
				}else{
					$this->success('新增成功！', U('index'));
				}
			}
		}else{
			$cateName = M('Category')->where(array('id'=>I('get.pid')))->getField('title');
			$this->assign('topName', $cateName ? $cateName : '无');
			$this->display();
		}
	}
}